home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / security / xinetd / compile-src < prev    next >
Encoding:
Text File  |  1993-06-28  |  10.4 KB  |  490 lines

  1. #!/bin/sh
  2.  
  3. #
  4. # (c) Copyright 1992 by Panagiotis Tsirigotis
  5. # All rights reserved.
  6. #
  7.  
  8. #
  9. # $Id: compile-src,v 5.6 1993/01/06 16:59:22 panos Exp $
  10. #
  11.  
  12. script_name=`basename $0`
  13.  
  14. if test "$script_name" != "$0" -a "./$script_name" != "$0" ; then
  15.    echo This script must be executed from the top level directory 
  16.    exit 1
  17. fi
  18.  
  19. #
  20. # misc needs to precede sio in the list of libraries
  21. #
  22. lib_names="sio misc fsma pset xlog str"
  23.  
  24. catch_sigs="2 15"
  25. inc=/usr/include
  26.  
  27. while test $# -gt 0
  28. do
  29.     option=$1 ; shift
  30.     case $option in
  31.         -libc)
  32.                 if test $# -eq 0 ; then
  33.                     echo "Argument missing. Exiting..."
  34.                     exit 1
  35.                 fi
  36.                 libc=$1
  37.                 shift
  38.                 if test ! -r $libc ; then
  39.                     echo "File is not readable: $libc"
  40.                     exit 1
  41.                 fi
  42.                 ;;
  43.  
  44.         -os)
  45.                 if test $# -eq 0 ; then
  46.                     echo "Argument missing. Exiting..."
  47.                     exit 1
  48.                 fi
  49.                 osversion=$1 ;
  50.                 shift
  51.                 ;;
  52.         
  53.         -auto)
  54.                 autoconfig=yes
  55.                 ;;
  56.  
  57.         -sf|-cf)
  58.                 if test $# -eq 0 ; then
  59.                     echo "Missing argument to $option. Exiting..."
  60.                     exit 1
  61.                 fi
  62.                     
  63.                 if test "$option" = "-sf" ; then
  64.                     v=yes
  65.                 else
  66.                     v=no
  67.                 fi
  68.  
  69.                 specified_flags=yes
  70.                 flag=$1
  71.                 shift
  72.  
  73.                 #
  74.                 # The first 2 lines are for xinetd. The 2nd line is related to 
  75.                 # signal handling.
  76.                 # The 3rd line has to do with the man pages (xinetd and libraries)
  77.                 # The 4th line is for the libraries
  78.                 #
  79.                 case "$flag" in
  80.                     old_wait|no_rpc|no_termios|no_posix_types)    eval $flag=$v ;;
  81.                     no_posix_sigs|no_sigvec|no_siglist)                eval $flag=$v ;;
  82.                     has_SB)                                                    eval $flag=$v ;;
  83.                     old_dir|no_ftw|no_syslog)                            eval $flag=$v ;;
  84.                     *)    echo "Bad flag name: $flag. Exiting..." ; exit 1
  85.                 esac
  86.                 ;;
  87.  
  88.         -verbose)
  89.                 verbose=yes
  90.                 ;;
  91.         #
  92.         # THIS IS THE SCRIPT DOCUMENTATION
  93.         #
  94.         -help)
  95.             echo "Usage: $script_name [options]"
  96.             echo "Options:"
  97.             echo "   -libc: specifies the location of the C library"
  98.             echo "   -os osname: specifies the OS name and version"
  99.             echo "    -auto: automatic configuration"
  100.             echo "    -verbose: display info about configuration"
  101.             echo "Possible arguments to -os:"
  102.             echo "        sunos4, ultrix4"
  103.             echo "   -sf flag or -cf flag:"
  104.             echo "         set or clear flags that specify what facilities"
  105.             echo "         are available from the operating system"
  106.             echo "Possible arguments to -sf and -cf:"
  107.             echo "         old_wait, no_rpc, no_termios, no_posix_types,"
  108.             echo "         no_posix_sigs, no_sigvec, no_siglist, has_SB,"
  109.             echo "         old_dir, no_ftw, no_syslog"
  110.             echo "The -sf/-cf flags can be specified multiple times."
  111.             echo "You can use the -os option to specify an operating system"
  112.             echo "and then you can use -sf/-cf for further mods."
  113.             exit 2
  114.             ;;
  115.  
  116.         *) echo "Bad argument: $1. Exiting..." ; exit 1
  117.     esac
  118. done
  119.  
  120. if test "$autoconfig" -a "$osversion" ; then
  121.     echo "Only one of -auto, -os can be specified"
  122.     exit 1
  123. fi
  124.  
  125. if test ! "$osversion" -a ! "$autoconfig" ; then
  126.     echo "I need to know the operating system you are using and the version."
  127.     echo "I know about"
  128.     echo "   SunOS 4.x (sunos4)"
  129.     echo "   Ultrix 4.x (ultrix4)"
  130.     echo "If your OS is among these, use the name in the parentheses, otherwise"
  131.     echo "just hit <return> and I will try to figure out how to properly"
  132.     echo -n "configure xinetd for your system --> "
  133.     read osversion
  134. fi
  135.  
  136. #
  137. # This if statement checks if we have a known osversion.
  138. # If we don't, we set the autoconfig flag.
  139. #
  140. if test "$osversion" ; then
  141.     case $osversion in
  142.         sunos4|ultrix4) autoconfig= ;;
  143.         *) echo "I don't know anything about this OS. Exiting..." ; exit 1
  144.     esac
  145. else
  146.     autoconfig=yes
  147. fi
  148.  
  149. #
  150. # Get namelist of C library
  151. #
  152. if test "$autoconfig" ; then
  153.     echo "Obtaining name list of your C library"
  154.  
  155.     if test ! "$libc" ; then
  156.         if test -r /lib/libc.a ; then
  157.             libc=/lib/libc.a
  158.         else
  159.             if test -r /usr/lib/libc.a ; then
  160.                 libc=/usr/lib/libc.a
  161.             else
  162.                 echo -n "Please give me the pathname of your C library -> "
  163.                 read libc
  164.                 if test ! "$libc" -o ! -r "$libc" ; then
  165.                     echo "Bad pathname. Exiting..."
  166.                     exit 1
  167.                 fi
  168.             fi
  169.         fi
  170.     fi
  171.     nmfile=/tmp/libc.nm.$$
  172.     nm $libc > $nmfile 2>/dev/null
  173.     if test $? -ne 0 ; then
  174.         echo "Couldn't get the namelist of your C library. Exiting..."
  175.         exit 1
  176.     fi
  177. fi
  178.  
  179. if test "$specified_flags" -o "$autoconfig" ; then
  180.     lib_defs=
  181.     xinetd_defs=
  182.  
  183.     #
  184.     # Determine supported signal handing
  185.     #
  186.     case "$no_posix_sigs" in
  187.         yes)    v=-DNO_POSIX_SIGS
  188.                 case "$no_sigvec" in
  189.                     yes)    w=-DNO_SIGVEC ;;
  190.                     no)    w= ;;
  191.                     *)        if test "$autoconfig" ; then
  192.                                 if test "$verbose" ; then echo "Looking for sigvec" ; fi
  193.                                 found=`grep sigvec $nmfile | grep T`
  194.                                 if test ! "$found" ; then w="-DNO_SIGVEC" ; else w= ; fi
  195.                             else
  196.                                 w=
  197.                             fi
  198.                 esac
  199.                 v="$v $w"
  200.                 ;;
  201.         no)    v= ;;
  202.         *)        if test "$autoconfig" ; then
  203.                     if test "$verbose" ; then echo "Looking for sigaction" ; fi
  204.                     found=`grep sigaction $nmfile | grep T`
  205.                     if test "$found" ; then
  206.                         v=
  207.                     else
  208.                         if test "$verbose" ; then echo "Looking for sigvec" ; fi
  209.                         found=`grep sigvec $nmfile | grep T`
  210.                         if test "$found" ; then 
  211.                             v="-DNO_POSIX_SIGS"
  212.                         else
  213.                             v="-DNO_POSIX_SIGS -DNO_SIGVEC"
  214.                         fi
  215.                     fi
  216.                 else
  217.                     v=
  218.                 fi
  219.     esac
  220.     xinetd_defs="$xinetd_defs $v"
  221.  
  222.     #
  223.     # Check for sys_siglist
  224.     #
  225.     case "$no_siglist" in
  226.         yes)    v=-DNO_SIGLIST ;;
  227.         no)    v= ;;
  228.         *)
  229.                 if test "$autoconfig" ; then
  230.                     if test "$verbose" ; then echo "Looking for sys_siglist" ; fi
  231.                     found=`grep sys_siglist $nmfile | grep D`
  232.                     if test ! "$found" ; then v=-DNO_SIGLIST ; else v= ; fi
  233.                 else
  234.                     v=
  235.                 fi
  236.     esac
  237.     xinetd_defs="$xinetd_defs $v"
  238.  
  239.     #
  240.     # Check for RPC
  241.     #
  242.     case "$no_rpc" in
  243.         yes)    v=-DNO_RPC ;;
  244.         no)    v= ;;
  245.         *)
  246.                 if test "$autoconfig" ; then
  247.                     if test "$verbose" ; then echo "Looking for RPC" ; fi
  248.                     found=`grep rpcent $inc/netdb.h`
  249.                     if test ! "$found" ; then v=-DNO_RPC ; else v= ; fi
  250.                 else
  251.                     v=
  252.                 fi
  253.     esac
  254.     xinetd_defs="$xinetd_defs $v"
  255.  
  256.     #
  257.     # Check if this system supports the old wait
  258.     #
  259.     case "$old_wait" in
  260.         yes)    v=-DOLD_WAIT ;;
  261.         no)    v= ;;
  262.         *)
  263.             if test "$autoconfig" ; then
  264.                 if test "$verbose" ; then echo "Looking for WEXITSTATUS" ; fi
  265.                 found=`grep WEXITSTATUS $inc/sys/wait.h`
  266.                 if test ! "$found" ; then v=-DOLD_WAIT ; else v= ; fi
  267.             else
  268.                 v=
  269.             fi
  270.     esac
  271.     xinetd_defs="$xinetd_defs $v"
  272.  
  273.     #
  274.     # Check for pid_t
  275.     # 
  276.     case "$no_posix_types" in
  277.         yes)    v=-DNO_POSIX_TYPES ;;
  278.         no)    v= ;;
  279.         *)
  280.             if test "$autoconfig" ; then
  281.                 if test "$verbose" ; then echo "Looking for pid_t" ; fi
  282.                 found=`cd $inc/sys ; grep pid_t *.h | grep typedef`
  283.                 if test ! "$found" ; then v=-DNO_POSIX_TYPES ; else v= ; fi
  284.             else
  285.                 v=
  286.             fi
  287.     esac
  288.     xinetd_defs="$xinetd_defs $v"
  289.  
  290.     #
  291.     # Check for termios
  292.     #
  293.     case "$no_termios" in
  294.         yes)    v=-DNO_TERMIOS ;;
  295.         no)    v= ;;
  296.         *)
  297.             if test "$autoconfig" ; then
  298.                 if test -r $inc/sys/termios.h -o -r $inc/termios.h ; then
  299.                     v=
  300.                 else
  301.                     v=-DNO_TERMIOS
  302.                 fi
  303.             else
  304.                 v=
  305.             fi
  306.     esac
  307.     xinetd_defs="$xinetd_defs $v"
  308.  
  309.     #
  310.     # Check for new directory types
  311.     #
  312.     case "$old_dir" in
  313.         yes)    v=-DOLD_DIR ;;
  314.         no)    v= ;;
  315.         *)
  316.                 if test "$autoconfig" ; then
  317.                     if test -r $inc/dirent.h ; then
  318.                         v=
  319.                     else
  320.                         v=-DOLD_DIR
  321.                     fi
  322.                 else
  323.                     v=
  324.                 fi
  325.     esac
  326.     lib_defs="$lib_defs $v"
  327.  
  328.     #
  329.     # Check for ftw(3)
  330.     #
  331.     case "$no_ftw" in
  332.         yes)    v=-D__FTWX_NO_FTW ;;
  333.         no)    v= ;;
  334.         *)
  335.                 if test "$autoconfig" ; then
  336.                     if test -r $inc/ftw.h ; then 
  337.                         v=
  338.                     else
  339.                         v=-D__FTWX_NO_FTW
  340.                     fi
  341.                 else
  342.                     v=
  343.                 fi
  344.     esac
  345.     lib_defs="$lib_defs $v"
  346.  
  347.     #
  348.     # Check for syslog(3)
  349.     #
  350.     case "$no_syslog" in
  351.         yes)    v=-DNO_SYSLOG ;;
  352.         no)    v= ;;
  353.         *)
  354.                 if test "$autoconfig" ; then
  355.                     if test "$verbose" ; then echo "Looking for syslog" ; fi
  356.                     found=`grep syslog $nmfile | grep T`
  357.                     if test ! "$found" ; then v=-DNO_SYSLOG ; else v= ; fi
  358.                 else
  359.                     v=
  360.                 fi
  361.     esac
  362.     lib_defs="$lib_defs $v"
  363. fi
  364.  
  365. if test "$autoconfig" ; then
  366.     rm -f $nmfile
  367. fi
  368.  
  369. #
  370. # Manually supply the link to the right configuration file.
  371. #
  372. rm -f libs/sio/sioconfig.h
  373. case "$osversion" in
  374.     sunos4) ln -s Config/sunos4.1-config.h libs/sio/sioconfig.h ;;
  375.     ultrix4) ln -s Config/ultrix4.1-config.h libs/sio/sioconfig.h ;;
  376.     *)
  377.         ans=
  378.         while [ "$ans" != "sysv" -a "$ans" != "bsd" ] 
  379.         do
  380.             echo "Is your OS based on System V or on BSD 4.x ? I am really"
  381.             echo -n "interested in terminal handling. You can say sysv or bsd -->"
  382.             read ans
  383.             case $ans in
  384.                 sysv) ln -s Config/sysv-config.h libs/sio/sioconfig.h ;;
  385.                 bsd) ln -s Config/bsd43-config.h libs/sio/sioconfig.h ;;
  386.                 *) echo "Please say either 'sysv' or 'bsd'"
  387.             esac
  388.         done
  389. esac
  390.  
  391. PWD=`pwd`
  392.  
  393. incdir=$PWD/libs/include
  394. mandir=$PWD/libs/man
  395. libdir=$PWD/libs/lib
  396.  
  397. #
  398. # Only Suns undestand .SB in man pages, so if we are not dealing with
  399. # a Sun we replace .SB with .B
  400. #
  401. if test "$osversion" = "sunos4" ; then
  402.     modify_manpages=
  403. else
  404.     case "$has_SB" in
  405.         yes) modify_manpages= ;;
  406.         no)  modify_manpages=yes ;;
  407.         *)
  408.         echo -n "Can your machine handle .SB in a man page ? (if you are not sure, say no) -->"
  409.         read x
  410.         if test "$x" = "n" -o "$x" = "no" ; then
  411.             modify_manpages=yes
  412.         else
  413.             modify_manpages=
  414.         fi
  415.     esac
  416. fi
  417.  
  418. if test "$modify_manpages" ; then
  419.     #
  420.     # We can't take any interrupts while processing the manpages
  421.     #
  422.     trap 'interrupt_occured=yes' $catch_sigs
  423.  
  424.     echo "Replacing .SB in library man pages with .B (if a man page is changed"
  425.     echo "the original will be kept by appending .orig to its name)"
  426.     for i in $lib_names
  427.     do
  428.         cd $PWD/libs/$i
  429.         for i in *.3
  430.         do
  431.             mv $i $i.orig                                            # save the original
  432.             sed 's/[.]SB/.B/' $i.orig > $i                    # do the replacement
  433.             cmp -s $i $i.orig                                        # are they the same ?
  434.             if test $? -eq 0 ; then rm $i.orig ; fi        # if yes, remove the copy
  435.         done
  436.         if test "$interrupt_occured" = "yes" ; then
  437.             echo "Interrupt: quiting"
  438.             exit 1
  439.         fi
  440.     done
  441.  
  442.     trap $catch_sigs        # no more trapping
  443. fi
  444.  
  445. #
  446. # Make the libraries
  447. #
  448. mvars="DEBUG=-O MANDIR=$mandir INCLUDEDIR=$incdir LIBDIR=$libdir"
  449. for i in $lib_names
  450. do
  451.     cd $PWD/libs/$i
  452.     echo Making library: $i
  453.     make $mvars DEFS="$lib_defs" install
  454.     if test $? -ne 0 ; then
  455.         echo "Failed to create library: $i"
  456.         exit 2
  457.     fi
  458. done
  459.  
  460. #
  461. # Now make xinetd
  462. # We remove the xinetd executable, if there is one, in case the libraries
  463. # have changed
  464. #
  465. cd $PWD/xinetd
  466. rm -f xinetd
  467. mvars="DEBUG=-O INCLUDEDIR=-I$incdir LDFLAGS=-L$libdir"
  468. make "DEFS=$xinetd_defs" $mvars
  469. if test $? -ne 0 ; then
  470.     echo Failed to create xinetd
  471.     exit 2
  472. fi
  473.  
  474. if test "$modify_manpages" ; then
  475.  
  476.     trap 'interrupt_occured=yes' $catch_sigs
  477.  
  478.     echo "Replacing .SB in xinetd man page with .B"
  479.     i=xinetd.1
  480.     mv $i $i.orig
  481.     sed 's/[.]SB/.B/' $i.orig > $i
  482.  
  483.     if test "$interrupt_occured" = "yes" ; then
  484.         echo "Interrupt: quiting"
  485.         exit 1
  486.     fi
  487.     trap $catch_sigs        # no more trapping
  488. fi
  489.  
  490.